package logic

import (
	"context"
	"renting-demo/house_srv/house"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListHouseLogic {
	return &ListHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListHouseLogic) ListHouse(req *types.ListRequest) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.HouseServe.List(context.Background(), &house.ListRequest{
		UserId:  int64(req.UserId),
		HouseId: int64(req.HouseId),
		Page:    int64(req.Page),
		Search:  req.Search,
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    10001,
			Message: "房源列表获取失败",
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "房源列表获取成功",
	}, nil
}
